package com.dly.hope.workflow;

import com.dly.hope.modle.BaseEntity;
import com.dly.hope.modle.UserAccount;
import com.dly.hope.workflow.type.FlagEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.Date;

/**
* @Name: NodeInstance
* @Description: 节点实例
* @Author: Danny Chen
* @Date: 2022/1/18
*/
@Entity
@Table(name = "wfl006_node_instance")
@Data
@DynamicInsert
@DynamicUpdate
public class NodeInstance extends BaseEntity {

    @Id
    @GenericGenerator(name = "uuid", strategy = "org.hibernate.id.UUIDGenerator")
    @GeneratedValue(generator = "uuid")
    @Column(name = "id", nullable = false)
    private String id;

    /**
     * 流程实例ID
     */
    @Column(name = "process_instance_id")
    private String processInstanceId;

    /**
     * 节点定义ID
     */
    @Column(name = "node_id")
    private String nodeId;

    /**
     * 节点定义对象
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "node_id", updatable = false, insertable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    private NodeInfo nodeInfo;

    /**
     * 实际审批人角色ID
     */
    //@Column(name = "approver_role_id")
    //private String approverRoleId;

    /**
     * 实际审批人ID
     */
    @Column(name = "approver_id")
    private String approverId;

    /**
     * 实际审批人对象
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "approver_id", updatable = false, insertable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    private UserAccount approver;

    /**
     * 是否完成，1：是，2：否，默认2
     */
    @Column(name = "complete_flag")
    private Integer completeFlag = FlagEnum.NO.getCode();

    /**
     * 审批结果
     */
    @Column(name = "appr_result")
    private String apprResult;

    /**
     * 审批意见
     */
    @Column(name = "suggestion")
    private String suggestion;

    /**
     * 显示序号（后面实例依次+1）'
     */
    @Column(name = "display_no")
    private Integer displayNo;

    /**
     * 实际上一个节点
     */
    //@Column(name = "pre_node_id")
    //private String preNodeId;

    /**
     * 实际下一个节点
     */
    @Column(name = "next_node_id")
    private String nextNodeId;

    /**
     * 业务数据，JSON格式
     */
    @Column(name = "data")
    private String data;

    /**
     * 备注
     */
    @Column(name = "remark")
    private String remark;

    /**
     * 审批时间
     */
    @Column(name = "appr_date")
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy.MM.dd HH:mm:ss", timezone = "GMT+08:00")
    private Date apprDate;

    /**
     * 是否处于当前活动的审批流程, 1:是，2:否
     */
    @Column(name = "active_flag")
    private Integer activeFlag = FlagEnum.YES.getCode();

}
